package com.shyt.impl;

import com.shyt.dao.RoleMenuSqRequstVo;
import com.shyt.dao.SysPermissionVo;
import com.shyt.dao.SysRoleVo;
import com.shyt.mapper.SysPermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SysPermissionServiceImpl {
    @Autowired
    SysPermissionMapper sysPermissionMapper;

    public List<SysPermissionVo> selectPermissions(Map rcMap){
        return sysPermissionMapper.selectPermissions(rcMap);
    }

    public List<SysPermissionVo> selectPermissionsByUser(Map rcMap){
        return sysPermissionMapper.selectPermissionsByUser(rcMap);
    }

    public void addMenu(SysPermissionVo sysPermissionVo) {
        sysPermissionMapper.addMenu(sysPermissionVo);
    }

    public List<SysPermissionVo> selectMenuXlk() {
        return sysPermissionMapper.selectMenuXlk();
    }


    public List<SysPermissionVo> selectAllMenus(SysPermissionVo sysPermissionVo) {

        return sysPermissionMapper.selectAllMenus(sysPermissionVo);
    }

    public List<SysPermissionVo> selectMenuTypeXlk() {
        return sysPermissionMapper.selectMenuTypeXlk();
    }

    public void editMenu(SysPermissionVo sysPermissionVo) {
         sysPermissionMapper.editMenu(sysPermissionVo);
    }

    public List<SysRoleVo> selectRolesByMeunId(SysPermissionVo sysPermissionVo) {
        return sysPermissionMapper.selectRolesByMeunId(sysPermissionVo);
    }

    public List<SysRoleVo> selectWSQRolesByMeunId(SysPermissionVo sysPermissionVo) {
        return sysPermissionMapper.selectWSQRolesByMeunId(sysPermissionVo);
    }

    public void roleMenuEdit(RoleMenuSqRequstVo roleMenuSqRequstVo) {
        List<String> roles = roleMenuSqRequstVo.getRoles();

        sysPermissionMapper.deleteRolePermisson(roleMenuSqRequstVo.getId());

        for (String roleId : roles) {
               sysPermissionMapper.insertRoleMenuEdit(roleMenuSqRequstVo.getId(),roleId);
        }


    }


    public void deleteMenuRoles(SysPermissionVo sysPermissionVo) {
        sysPermissionMapper.deleteById(sysPermissionVo.getId());
        sysPermissionMapper.deleteMenuRoles(sysPermissionVo);
    }
}
